#version 330

struct Light
{
	vec3 Color;
	vec3 Dir;
	float Ambient;
};

uniform sampler2D T2_COMPOS_NORM_DEPTH;
uniform sampler2D T2_COMPOS_ALBEDO;
uniform mat3 M3_CAMERA_FROM_WORLD;
uniform ivec2 V2_VIEWPORT_DIM;
uniform int I1_NUM_LIGHTS;

uniform Light LIGHTS[4];


layout (location = 0) out vec4 oOutput;

void main()
{
	vec2 UV = gl_FragCoord.xy / V2_VIEWPORT_DIM.xy;
    
    vec4 NormDepth = texture(T2_COMPOS_NORM_DEPTH, UV);
	vec3 Norm = normalize(NormDepth.xyz);
	float Depth = 1.0 - NormDepth.w;
    
    vec3 Albedo = texture(T2_COMPOS_ALBEDO, UV).xyz;
    
	vec3 TotalContrib = vec3(0);
	for (int i = 0; i < I1_NUM_LIGHTS; i++)
	{
		vec3 LightDir = normalize(M3_CAMERA_FROM_WORLD * LIGHTS[i].Dir);
		float NL = max(-dot(Norm, LightDir), LIGHTS[i].Ambient);
		vec3 LightContrib = LIGHTS[i].Color * NL;
		TotalContrib += LightContrib;
	}
	
	oOutput = vec4(TotalContrib * Albedo.xyz * Depth, 0.0);
}







